package com.alks.function.controller.finance.fincons;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RoleCheck;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.finance.fincons.AnnualPayableRequest;
import com.alks.function.data.request.finance.fincons.SettlementPayableRequest;
import com.alks.function.service.finance.fincons.AnnualPayableService;
import com.alks.function.service.finance.fincons.SettlementPayableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@Api(value = "财务部-工厂-财务咨询查询", tags = {"财务部-年度应付查询"})
@ApiRestController("/AnnualPayable")
@RoleCheck(prgIds = {"100504","180504"})
public class AnnualPayableController {

    @Autowired
    private AnnualPayableService annualPayableService;

    @Autowired
    private SettlementPayableService settlementPayableService;

    @PostMapping("/getSettlementSummaryByAnnual")
    @ApiOperation(value = "查询结算应付汇总/年度,计算金额",tags = "财务部-年度应付查询")
    public ResponseInfo getSettlementPayableSummaryByAnnual(@RequestBody AnnualPayableRequest request) {
        //前端控制传入的结算年份
        return settlementPayableService.getSettlementSummaryByAnnual(request);
    }

    @PostMapping("/getSettlementSummaryDetails")
    @ApiOperation(value = "查询结算应付汇总/月份,计算金额",tags = "财务部-年度应付查询")
    public ResponseInfo getSettlementPayableSummary(@RequestBody SettlementPayableRequest request) {
        //必传：厂商、结算年份yy
        return settlementPayableService.getSettlementSummaryByMonth(request);
    }

    @PostMapping("/getPaymentDetailsAndMonthAndAmount")
    @ApiOperation(value = "查询付款明细/月份,计算总金额",tags = "财务部-年度应付查询")
    public ResponseInfo getPaymentDetailsAndMonthAndAmount (@RequestBody AnnualPayableRequest request) {
        //双击时把厂商和结算月份传进去
        return annualPayableService.getPaymentDetailsAndMonthAndAmount(request);
    }

    @WebLogger
    @PostMapping("/exportSettlementSummary")
    @ApiOperation(value = "导出（结算应付汇总/年度查询）",tags = "财务部-年度应付查询")
    public void exportSettlementSummary(@RequestBody AnnualPayableRequest request, HttpServletResponse response) throws IOException {
        annualPayableService.exportSettlementSummary(request,response);
    }

    @WebLogger
    @GetMapping("/exportReconciliationStatistics")
    @ApiOperation(value = "导出对账统计表",tags = "财务部-年度应付查询")
    public void exportReconciliationStatistics( @ApiParam(value = "结算年份",required = true)  @RequestParam String financeYear,  HttpServletResponse response) throws IOException {
        annualPayableService.exportReconciliationStatistics(financeYear,response);
    }

    @WebLogger
    @PostMapping("/exportPaymentDetails")
    @ApiOperation(value = "导出付款明细",tags = "财务部-年度应付查询")
    public void exportPaymentDetails(@RequestBody AnnualPayableRequest request, HttpServletResponse response) throws IOException {
        annualPayableService.exportPaymentDetails(request,response);
    }

    @WebLogger
    @GetMapping("/updateStatistics")
    @ApiOperation(value = "更新对账数据",tags = "财务部-年度应付查询")
    public ResponseInfo updateStatistics( )  {
        return annualPayableService.updateStatistics();
    }

}
